package masterjava.common.property;

import masterjava.common.logging.MasterLogger;

/**
 * MasterJava.ru
 * <p/>
 * User: GKislin
 * Date: 17.04.11
 */
public abstract class ConvertAdapter<T> implements IConverter<T> {
    protected static final MasterLogger LOGGER = MasterLogger.get(ConvertAdapter.class);

    @Override
    public T toValue(String property) {
        try {
            return convert(property);
        } catch (Exception e) {
            throw LOGGER.getIllegalArgumentException(property + " coudn't be converted", e);
        }
    }

    abstract protected T convert(String property) throws Exception;

    @Override
    public String toString(T value) {
        return value == null ? null : value.toString();
    }
}
